package org.bigk.invoices.exceptions;

import org.hibernate.HibernateException;

public class ServiceException extends Exception {

	private static final long serialVersionUID = 9057893107799323613L;

	private String errorCode;
	private Object[] errorCodeParams;

	public ServiceException() {
		super();
	}

	public ServiceException(String message, Throwable cause) {
		super(message, cause);
	}

	public ServiceException(String message) {
		super(message);
	}

	public ServiceException(Throwable cause) {
		super(cause);
	}

	public ServiceException(String message, String errorCode,
			Object[] errorCodeParams) {
		super(message);
		this.errorCode = errorCode;
		this.errorCodeParams = errorCodeParams;
	}

	public ServiceException(String message, Throwable cause, String errorCode,
			Object[] errorCodeParams) {
		super(message, cause);
		this.errorCode = errorCode;
		this.errorCodeParams = errorCodeParams;
	}

	public ServiceException(DBAccessException cause) {
		super(cause.getMessage(), cause);
		this.errorCode = cause.getErrorCode();
		this.errorCodeParams = cause.getErrorCodeParams();
	}

	public ServiceException(HibernateException cause) {
		super(cause.getMessage(), cause);
		this.setErrorCode("exceptions.DBAccessException_1Param");
		this.setErrorCodeParams(new Object[] {cause.getMessage()});
	}
	
	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	public Object[] getErrorCodeParams() {
		return errorCodeParams;
	}

	public void setErrorCodeParams(Object[] errorCodeParams) {
		this.errorCodeParams = errorCodeParams;
	}
}
